package com.zwz.shiro;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.subject.Subject;

/**
 * 重写perms
 * 2015年12月27日 下午8:04:25
 * @author zhangwanzhong 
 */
public class MyPermsAuthorizationFilter extends MyAuthorizationFilter {

	@Override
	protected boolean isAccessAllowed(ServletRequest request,
			ServletResponse response, Object mappedValue) throws Exception {
		Subject subject = getSubject(request, response);
		String[] perms = (String[]) mappedValue;

		boolean isPermitted = true;
		if (perms != null && perms.length > 0) {
			if (perms.length == 1) {
				if (!subject.isPermitted(perms[0])) {
					isPermitted = false;
				}
			} else {
				for (String perm : perms) {
					if(subject.isPermitted(perm)){
						isPermitted=true;
						break;
					}else{
						isPermitted = false;
					}
				}
			}
		}
		return isPermitted;
	}

}
